package com.ruoyi.web.controller.system.assets;

import java.util.List;

import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.assets.FzBuildingRoomType;
import com.ruoyi.system.domain.communiry.FzSCommunity;
import com.ruoyi.system.service.assets.IFzBuildingRoomTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpSession;

/**
 * 房屋类型Controller
 * 
 * @author ruoyi
 * @date 2020-02-28
 */
@Controller
@RequestMapping("/system/type")
public class FzBuildingRoomTypeController extends BaseController
{
    private String prefix = "system/assets/type";

    @Autowired
    private IFzBuildingRoomTypeService fzBuildingRoomTypeService;

    @RequiresPermissions("system:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询房屋类型列表
     */
    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HttpSession session,FzBuildingRoomType fzBuildingRoomType)
    {
        startPage();
        String communityId=((FzSCommunity)session.getAttribute("ycommunity")).getCommunityId();
        fzBuildingRoomType.setcId(communityId);
        List<FzBuildingRoomType> list = fzBuildingRoomTypeService.selectFzBuildingRoomTypeList(fzBuildingRoomType);
        return getDataTable(list);
    }

    /**
     * 导出房屋类型列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "房屋类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzBuildingRoomType fzBuildingRoomType)
    {
        List<FzBuildingRoomType> list = fzBuildingRoomTypeService.selectFzBuildingRoomTypeList(fzBuildingRoomType);
        ExcelUtil<FzBuildingRoomType> util = new ExcelUtil<FzBuildingRoomType>(FzBuildingRoomType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增房屋类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房屋类型
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "房屋类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzBuildingRoomType fzBuildingRoomType)
    {
        fzBuildingRoomType.setcId(GetSessionValueUtil.getCommunity());
        fzBuildingRoomType.setCreateBy(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzBuildingRoomTypeService.insertFzBuildingRoomType(fzBuildingRoomType));
    }

    /**
     * 修改房屋类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FzBuildingRoomType fzBuildingRoomType = fzBuildingRoomTypeService.selectFzBuildingRoomTypeById(id);
        mmap.put("fzBuildingRoomType", fzBuildingRoomType);
        return prefix + "/edit";
    }

    /**
     * 修改保存房屋类型
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "房屋类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzBuildingRoomType fzBuildingRoomType)
    {  fzBuildingRoomType.setUpdateBy(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzBuildingRoomTypeService.updateFzBuildingRoomType(fzBuildingRoomType));
    }

    /**
     * 删除房屋类型
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "房屋类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzBuildingRoomTypeService.deleteFzBuildingRoomTypeByIds(ids));
    }
}
